<template>
  <div class="rateRecovery secondary-page-mode">
    <div class="secondary-toolbar">
      <span>时间选择 : </span>&nbsp;
      <div class="layoutBox" style="width:242px">
        <el-date-picker v-model="dateRange" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </div>&emsp;&emsp;
      <span>监测项目 : </span>&nbsp;
      <div class="layoutBox" style="width:160px">
        <el-select v-model="value" collapse-tags placeholder="请选择" @change="">
          <el-option
            v-for="item in optionData"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </div>&emsp;&emsp;
      <el-button @click="searchData()"><i class="iconfont icon-sousuo"></i>查询</el-button>
      <el-button @click="exportExcel()" type='delet'><i class="iconfont icon-daochu"></i>导出</el-button>
    </div>
    <div class="currency-mode-wrap">
      <el-scrollbar style="height:100%">
        <div class="topul">
          <ul>
            <li v-for="(item,key) in toplist" :key="key">
                      <span>
                            <i></i>
                      </span>
              <p>{{item.name}} : <span>{{item.num}}</span></p>
            </li>
          </ul>
        </div>
        <div class="zTable">
          <table>
            <tr>
              <td colspan="6">
                <div>
                  <i></i>总体范围: {{ recoveryList.minValue }} 到 {{ recoveryList.maxValue }}
                </div>
              </td>
            </tr>
            <tr>
              <td width='10%' style="background:#e7f0f9;">回收率范围</td>
              <td width='18%'>90-100</td>
              <td  width='18%'>80-120</td>
              <td  width='18%'>70-130</td>
              <td  width='18%'>60-150</td>
              <td  width='18%'>其它</td>
            </tr>
            <tr>
              <td width='10%' style="background:#e7f0f9;">总项次</td>
              <td  width='18%'>{{ recoveryList.list[0].one }}</td>
              <td  width='18%'>{{ recoveryList.list[0].two}}</td>
              <td  width='18%'>{{ recoveryList.list[0].three }}</td>
              <td  width='18%'>{{ recoveryList.list[0].four}}</td>
              <td  width='18%'>{{ recoveryList.list[0].other}}</td>
            </tr>
            <tr>
              <td width='10%' style="background:#e7f0f9;">比重</td>
              <td  width='18%'>
                <div class="echarttd">
                  {{ recoveryList.list[1].one === ''? '-' : recoveryList.list[1].one}}</div>
              </td>
              <td  width='18%'>
                <div class="echarttd">
                  {{ recoveryList.list[1].two === '' ? '-' : recoveryList.list[1].two}}
                </div>
              </td>
              <td  width='18%'>
                <div class="echarttd">
                  {{ recoveryList.list[1].three === '' ? '-' : recoveryList.list[1].three}}
                </div>
              </td>
              <td  width='18%'>
                <div class="echarttd">
                  {{ recoveryList.list[1].four === '' ? '-' : recoveryList.list[1].four}}
                </div>
              </td>
              <td  width='18%'>
                <div class="echarttd">
                  {{ recoveryList.list[1].other === '' ? '-' : recoveryList.list[1].other}}
                </div>
              </td>
            </tr>
          </table>
        </div>
        <div id="rateRecoveryBar" class="rateRecoveryBar"></div>
        <div id="rateRecoveryLine" class="rateRecoveryLine"></div>
        <div class="table-wrap" style="margin-top: 10px;">
          <el-table
            :data="tableData"
            ref="table"
            border
            style="width: 100%">
            <el-table-column
              type="index"
              label="序号">
            </el-table-column>
            <el-table-column
              prop="time"
              label="时间">
            </el-table-column>
            <el-table-column
              prop="indexName"
              label="监测项目">
            </el-table-column>
            <el-table-column
              prop="value"
              label="测定值(mg/L)">
            </el-table-column>
            <el-table-column
              prop="standardSamplesValue"
              label="标样值(mg/L)">
            </el-table-column>
            <el-table-column
              prop="error"
              label="相对误差(%)">
            </el-table-column>
            <el-table-column
              prop="dataFlag"
              label="数据标记">
            </el-table-column>
            <el-table-column
              prop="technicalRequirement"
              label="技术要求">
            </el-table-column>
            <el-table-column
              prop="qualification"
              label="合格情况">
            </el-table-column>
          </el-table>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
  import {exportTableData} from '../../assets/js/tableExport'
  export default {
    name: "rateRecovery",
    data() {
      return {
        dateRange: [],
        value: 'w01019',
        toplist:[
          {
            name:'总项次',
            num:'0',
          },{
            name:'合格项次',
            num:'0',
          },{
            name:'不合格项次',
            num:'0',
          },{
            name:'合格率',
            num:'0%',
          }
        ],
        stationId:'',
        optionData:[],
        optionDataA: [
          {
            value: "w01019",
            label: "高锰酸盐"
          },
          {
            value: "w21003",
            label: "氨氮"
          },
          {
            value: "w21011",
            label: "总磷"
          },
          {
            value: "w21001",
            label: "总氮"
          }
        ],
        optionDataB:[
          {
            value: "w01018",
            label: "CODcr"
          },
          {
            value: "w21003",
            label: "氨氮"
          },
          {
            value: "w21011",
            label: "总磷"
          },
          {
            value: "w21001",
            label: "总氮"
          }
        ],
        hTableData: [
          {
            range: "90-100",
            totalItem: "0",
            proportion: "0.00"
          },
          {
            range: "80-120",
            totalItem: "0",
            proportion: "0.00"
          },
          {
            range: "70-130",
            totalItem: "0",
            proportion: "0.00"
          },
          {
            range: "60-150",
            totalItem: "0",
            proportion: "0.00"
          },
          {
            range: "其他",
            totalItem: "1",
            proportion: "100.00"
          }
        ],
        tableData: [
          {
            dateTime: "2019-02-25 13:11:05",
            monitoringItem: "高锰酸盐",
            measuredValue: "3.1",
            waterSample: "7",
            concentration: "1000",
            volume: "1.4",
            afterBidding: "200",
            rateRecovery: "57.11"
          }
        ],
        recoveryList:{
          list:[{
            one:'',
            two:'',
            three:'',
            four:'',
            other:''
          },{
            one:'',
            two:'',
            three:'',
            four:'',
            other:''
          }],
          maxValue:'',
          minValue:''
        },
        barChart: '',
        lineChart:'',
        stationName:'',
        fieldList:['time','indexName','value','standardSamplesValue','error','dataFlag','technicalRequirement','qualification']
      };
    },
    methods: {
      //创建柱状图
      createRateRecoveryBar(data) {
        let chart = this.$echarts.init(
          document.getElementById("rateRecoveryBar")
        );
        let name = this.contrastFactor(this.value);
        data.series.forEach((item,index)=>{
          item.barWidth = 20;
        });
        chart.clear();
        if(data.xAxis.length === 0){
          return false;
        }
        let option = {
          color:['#8e42ff','#00a3f5','#1cad8b','#1ebd1e','#c2a100'],
          tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
              type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            formatter:'{b}<br/>{a0}: {c0} <br/>{a1}: {c1} <br/>{a2}: {c2} <br/>{a3}: {c3} %'
          },
          title: {
            text: name+" 标样核查-柱状图",
            x: "center",
            textStyle: {
              fontWeight: 100,
              color: "#166bce"
            }
          },
          grid: {
            left: 60,
            right: 60,
            bottom: 20
          },
          xAxis: {
            type: "category",
            name: "时间",
            nameTextStyle: {
              color: "#166bce"
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#c6d1de"
              }
            },
            axisLabel: {
              color: "#333"
            },
            data: data.xAxis/*[
            "2019/02/01 16时",
            "2019/02/02 16时",
            "2019/02/03 16时",
            "2019/02/04 16时",
            "2019/02/05 16时",
            "2019/02/06 16时",
            "2019/02/07 16时"
          ]*/
          },
          yAxis: {
            type: "value",
            name: "误差（%）",
            nameTextStyle: {
              color: "#166bce"
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#c6d1de"
              }
            },
            axisLabel: {
              color: "#333"
            }
          },
          series: data.series/*[
          {
            data: data.series,//[120, 110, 115, 88, 90, 101, 112],
            type: "bar",
            barWidth: 20,
            itemStyle:{
              color:'#00a1e4'
            }
          }
        ]*/
        };
        chart.setOption(option);
      },
      //创建线性图
      createRateRecoveryLine(data) {
        let chart = this.$echarts.init(
          document.getElementById("rateRecoveryLine")
        );
        let name = this.contrastFactor(this.value);
        let option = {
          color: ["#8ca8c8"],
          title: {
            text: name+" 标样核查-曲线图",
            x: "center",
            y: 10,
            textStyle: {
              fontWeight: 100,
              color: "#166bce"
            }
          },
          tooltip : {
            trigger: 'axis',
            formatter:'{b}<br/>{a}: {c} %'
          },
          grid: {
            left: 60,
            right: 60,
            bottom: 20
          },
          xAxis: {
            type: "category",
            name: "时间",
            nameTextStyle: {
              color: "#166bce"
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#c6d1de"
              }
            },
            axisLabel: {
              color: "#333"
            },
            data: data.xAxis /*[
            "2019/02/01 16时",
            "2019/02/02 16时",
            "2019/02/03 16时",
            "2019/02/04 16时",
            "2019/02/05 16时",
            "2019/02/06 16时",
            "2019/02/07 16时"
          ]*/
          },
          yAxis: {
            type: "value",
            name: "误差（%）",
            nameTextStyle: {
              color: "#166bce"
            },
            axisLine: {
              lineStyle: {
                width: 2,
                color: "#c6d1de"
              }
            },
            axisLabel: {
              color: "#333"
            }
          },
          series: [
            {
              name:'标样核查',
              data: data.yAxis,//[120, 110, 115, 88, 90, 101, 112],
              type: "line",
              barWidth: 20,
              itemStyle:{
                color:'#00a1e4'
              },
              markLine: {
                data: [{ yAxis: parseFloat(data.lower) },{ yAxis: parseFloat(data.upper) }]
              }
            }
          ]
        };
        chart.clear();
        chart.setOption(option);
      },
      //获取加标样核查相关占比数据
      getRecoveryRatioData(){
        this.$http.get("/Quality/testData/verificationOfStandardSamplesRatioData", {
          params: {
            startTime: this.dateRange[0].format('yyyy-MM-dd hh:mm:ss'),
            endTime: this.dateRange[1].format('yyyy-MM-dd hh:mm:ss'),
            indexCodes: this.value,
            stationCodes: this.stationId, //this.stationId
            ifCurrentSection: true,// true为当前断面,false为所有
          }
        }).then(res=>{
          if(res.data.code === 0){
            this.recoveryList = res.data.content.info;
            this.toplist[0].num = res.data.content.info.count;
            this.toplist[1].num = res.data.content.info.qualifiedCount;
            this.toplist[2].num = res.data.content.info.noQualifiedCount;
            this.toplist[3].num = res.data.content.info.qualifiedRate;
          }
        })
      },
      //获取标样核查柱状图表数据
      getBarChartData(){
        this.$http.get("/Quality/testData/verificationOfStandardSamplesBarChartData", {
          params: {
            startTime: this.dateRange[0].format('yyyy-MM-dd hh:mm:ss'),
            endTime: this.dateRange[1].format('yyyy-MM-dd hh:mm:ss'),
            indexCodes: this.value,
            stationCodes: this.stationId, //this.stationId
            ifCurrentSection: true,// true为当前断面,false为所有
          }
        }).then(res=>{
          if(res.data.code === 0){
            this.barChart = res.data.content.info;
            this.createRateRecoveryBar(this.barChart);
          }
        })
      },
      //获取标样核查曲线图表数据
      getLineChartData(){
        this.$http.get("/Quality/testData/verificationOfStandardSamplesChartData", {
          params: {
            startTime: this.dateRange[0].format('yyyy-MM-dd hh:mm:ss'),
            endTime: this.dateRange[1].format('yyyy-MM-dd hh:mm:ss'),
            indexCodes: this.value,
            stationCodes: this.stationId, //this.stationId
            ifCurrentSection: true,// true为当前断面,false为所有
          }
        }).then(res=>{
          if(res.data.code === 0){
            this.lineChart = res.data.content.dataList[0];
            this.createRateRecoveryLine(this.lineChart);
          }
        })
      },
      //获取标样核查表格数据
      getRecoveryData(){
        this.$http.get("/Quality/testData/verificationOfStandardSamplesData", {
          params: {
            startTime: this.dateRange[0].format('yyyy-MM-dd hh:mm:ss'),
            endTime: this.dateRange[1].format('yyyy-MM-dd hh:mm:ss'),
            indexCodes: this.value,
            stationCodes: this.stationId, //this.stationId
            ifCurrentSection: true,// true为当前断面,false为所有
          }
        }).then(res=>{
          if(res.data.code === 0){
            this.tableData = res.data.content.dataList;
          }
        })
      },
      //根据编号筛选因子
      contrastFactor(code){
        for (let i=0; i < this.optionData.length ; i++){
          if(this.optionData[i].value === code){
            return this.optionData[i].label;
          }
        }
      },
      //点击查询事件
      searchData(){
        this.getRecoveryRatioData();
        this.getBarChartData();
        this.getLineChartData();
        this.getRecoveryData();
      },
      setOptionData(){
        if(this.stationType){
          this.optionData = this.optionDataB;
          this.value =  "w01018";
        }else{
          this.optionData = this.optionDataA;
          this.value =  "w01019";
        }
        this.searchData();
      },
      //导出表格
      exportExcel(){
        let {table} = this.$refs;
        let tableBox = table.$el;
        let header = tableBox.querySelector('.el-table__header');
        let title = this.stationName+'标样核查数据';
        let params = {
          headerProp:this.fieldList.join(','),
          startTime: this.dateRange[0].format('yyyy-MM-dd hh:mm:ss'),
          endTime: this.dateRange[1].format('yyyy-MM-dd hh:mm:ss'),
          indexCodes: this.value,
          stationCodes: this.stationId,
          tableType:'VERIFICATION_STANDARD_SAMPLES_DATA',
          ifCurrentSection: true,
          pattern:'yyyy-MM-dd'
        };
        exportTableData(header,title,'','1',"/Quality/exports/testDataExcel",params);
      }
    },
    mounted() {
      // this.createRateRecoveryBar();
      // this.createRateRecoveryLine();
    },
    created() {
      let start = new Date().setFullYear(new Date().getFullYear() - 1);
      let end = new Date();
      this.dateRange = [new Date(start),end];
    },
    computed: {
      stationInfo: {
        get: function() {
          return this.$store.state.stationInfo;
        }
      }
    },
    watch: {
      stationInfo(value) {
        if (value.length > 0) {
          this.stationId = value[0].nodeId;
          this.stationName = value[0].nodeName;
         if(value[0].stationType1 === '002'){
            this.stationType = true;
          
          }else{
            this.stationType = false;
           
          }
          this.setOptionData();
        }
      }
    }
  };
</script>

<style scoped lang="less">
  .rateRecovery {
    .topul{
      height: 70px;
      li{
        float: left;
        height: 70px;
        border: 1px solid #c7d8ee;
        width: 24%;
        margin-right: 1.33%;
        border-top: 3px solid #c7d8ee;
        padding-left: 80px;
        background: -webkit-linear-gradient(left, #01a1e4, #33b7ed);
        /* Safari 5.1 - 6.0 */
        background: -o-linear-gradient(right, #01a1e4, #33b7ed);
        /* Opera 11.1 - 12.0 */
        background: -moz-linear-gradient(right, #01a1e4, #33b7ed);
        /* Firefox 3.6 - 15 */
        background: linear-gradient(to right, #01a1e4, #33b7ed);
        /* 标准的语法 */
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#01a1e4', endColorstr='#33b7ed', GradientType=0);
        &:last-child{
          margin-right: 0;
        }
        >p{
          color: #fff;
          height: 70px;
          line-height: 70px;
          font-size: 13px;
          font-weight: 700;
          padding-left: 20%;
          >span{
            font-size: 15px;
            font-weight: 700;
          }
        }
      }
    }
    .zTable{
      margin-top: 12px;
      table{
        width: 100%;
        border-collapse: collapse;
        border: 1px solid #d6e3f2;
        text-align: center;
        td{
          border: 1px solid #d6e3f2;
        }
        tr{
          td{
            height: 30px;
            &:first-child{
              text-align: left;
              padding-left: 22px;
              font-weight: 700;
            }
            .echarttd{
              height: 65px;
              line-height: 65px;
              vertical-align: middle;
            }
          }
        }
      }
    }
    .rateRecoveryBar{
      height: 250px;
      margin-top: 12px;
    }
    .rateRecoveryLine{
      height: 250px;
      margin-top: 12px;
    }
  }
</style>
